import 'package:shared_preferences/shared_preferences.dart';

class ComicTypeManager {
  static const String _userTypeKey = 'user_type';
  static const String _mediaSourceKey = 'media_source';
  
  // 设置用户类型
  static Future<void> setUserType(String type, {String? mediaSource}) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(_userTypeKey, type);
    if (mediaSource != null) {
      await prefs.setString(_mediaSourceKey, mediaSource);
    }
  }
  
  // 获取comicType值
  static Future<String> getComicType() async {
    try {
      final prefs = await SharedPreferences.getInstance();
      final userType = prefs.getString(_userTypeKey);
      
      switch (userType) {
        case 'organic':
          return '0'; // 自然量用户
        case 'non_organic':
          return '1'; // 非自然量用户
        default:
          return '0'; // 默认值
      }
    } catch (e) {
      print('获取comicType失败: $e');
      return '0'; // 默认值
    }
  }
  
  // 获取用户类型
  static Future<String?> getUserType() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getString(_userTypeKey);
  }
  
  // 获取媒体来源
  static Future<String?> getMediaSource() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getString(_mediaSourceKey);
  }
}